﻿using System.ComponentModel;
using System.Windows.Forms;

namespace TAProject.UI
{
    static class AsyncWorker
    {
        public static void RunAcync(Form parentForm, DoWorkEventHandler doWorkEventHandler, RunWorkerCompletedEventHandler runWorkerCompletedEventHandler)
        {
            var backgroundWorker = new BackgroundWorker();
            var form = new FormProgressBar(parentForm);
            form.Show();

            backgroundWorker.DoWork += doWorkEventHandler;
            backgroundWorker.RunWorkerCompleted += runWorkerCompletedEventHandler;
            backgroundWorker.RunWorkerCompleted += delegate { form.Close(); };

            backgroundWorker.RunWorkerAsync();
        }
    }
}
